home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Direct3D / AutoParts / auto.frm next >
Text File  |  2001-10-08  |  24KB  |  877 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Form1 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Auto Collision Parts Database"
  6.    ClientHeight    =   8520
  7.    ClientLeft      =   480
  8.    ClientTop       =   615
  9.    ClientWidth     =   10875
  10.    Icon            =   "auto.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   568
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   725
  17.    Begin MSComctlLib.TreeView TreeView1 
  18.       Height          =   3495
  19.       Left            =   120
  20.       TabIndex        =   27
  21.       Top             =   480
  22.       Width           =   3975
  23.       _ExtentX        =   7011
  24.       _ExtentY        =   6165
  25.       _Version        =   393217
  26.       HideSelection   =   0   'False
  27.       Style           =   7
  28.       Appearance      =   1
  29.    End
  30.    Begin VB.TextBox Text8 
  31.       Enabled         =   0   'False
  32.       Height          =   375
  33.       Left            =   9000
  34.       TabIndex        =   25
  35.       Top             =   7380
  36.       Width           =   1695
  37.    End
  38.    Begin VB.PictureBox Picture2 
  39.       Height          =   735
  40.       Left            =   120
  41.       ScaleHeight     =   675
  42.       ScaleWidth      =   10515
  43.       TabIndex        =   19
  44.       Top             =   4080
  45.       Width           =   10575
  46.       Begin VB.Label Label9 
  47.          Caption         =   $"auto.frx":0442
  48.          Height          =   495
  49.          Left            =   120
  50.          TabIndex        =   20
  51.          Top             =   120
  52.          Width           =   9495
  53.       End
  54.    End
  55.    Begin VB.CommandButton Command1 
  56.       Caption         =   "Add To Invoice"
  57.       Height          =   495
  58.       Left            =   120
  59.       TabIndex        =   16
  60.       Top             =   7920
  61.       Width           =   3975
  62.    End
  63.    Begin MSComctlLib.ListView ListView1 
  64.       Height          =   2355
  65.       Left            =   4320
  66.       TabIndex        =   15
  67.       Top             =   4920
  68.       Width           =   6375
  69.       _ExtentX        =   11245
  70.       _ExtentY        =   4154
  71.       View            =   3
  72.       LabelWrap       =   -1  'True
  73.       HideSelection   =   0   'False
  74.       _Version        =   393217
  75.       ForeColor       =   -2147483640
  76.       BackColor       =   -2147483643
  77.       BorderStyle     =   1
  78.       Appearance      =   1
  79.       NumItems        =   5
  80.       BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  81.          Key             =   "price"
  82.          Text            =   "DESCRIPTION"
  83.          Object.Width           =   5821
  84.       EndProperty
  85.       BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  86.          SubItemIndex    =   1
  87.          Key             =   "part"
  88.          Text            =   "PRICE"
  89.          Object.Width           =   2117
  90.       EndProperty
  91.       BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  92.          SubItemIndex    =   2
  93.          Key             =   "id"
  94.          Text            =   "ID"
  95.          Object.Width           =   2117
  96.       EndProperty
  97.       BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  98.          SubItemIndex    =   3
  99.          Key             =   "modid"
  100.          Text            =   "MODID"
  101.          Object.Width           =   0
  102.       EndProperty
  103.       BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  104.          SubItemIndex    =   4
  105.          Object.Width           =   38100
  106.       EndProperty
  107.    End
  108.    Begin VB.CommandButton Command3 
  109.       Caption         =   "Process Order"
  110.       Height          =   495
  111.       Left            =   7680
  112.       TabIndex        =   3
  113.       Top             =   7920
  114.       Width           =   3015
  115.    End
  116.    Begin VB.CommandButton Command2 
  117.       Caption         =   "Remove From Invoice"
  118.       Height          =   495
  119.       Left            =   4320
  120.       TabIndex        =   2
  121.       Top             =   7920
  122.       Width           =   3135
  123.    End
  124.    Begin VB.PictureBox largepict 
  125.       Height          =   3495
  126.       Left            =   4320
  127.       ScaleHeight     =   229
  128.       ScaleMode       =   3  'Pixel
  129.       ScaleWidth      =   421
  130.       TabIndex        =   1
  131.       Top             =   480
  132.       Width           =   6375
  133.    End
  134.    Begin VB.PictureBox Picture1 
  135.       Height          =   2835
  136.       Left            =   120
  137.       ScaleHeight     =   2775
  138.       ScaleWidth      =   3915
  139.       TabIndex        =   0
  140.       Top             =   4920
  141.       Width           =   3975
  142.       Begin VB.TextBox Text7 
  143.          Enabled         =   0   'False
  144.          Height          =   285
  145.          Left            =   1440
  146.          TabIndex        =   26
  147.          Top             =   2400
  148.          Width           =   1695
  149.       End
  150.       Begin VB.TextBox Text6 
  151.          Enabled         =   0   'False
  152.          Height          =   285
  153.          Left            =   1440
  154.          TabIndex        =   24
  155.          Top             =   2040
  156.          Width           =   1695
  157.       End
  158.       Begin VB.TextBox Text5 
  159.          Enabled         =   0   'False
  160.          Height          =   285
  161.          Left            =   1440
  162.          TabIndex        =   13
  163.          Top             =   1680
  164.          Width           =   1695
  165.       End
  166.       Begin VB.TextBox Text4 
  167.          Enabled         =   0   'False
  168.          Height          =   285
  169.          Left            =   1440
  170.          TabIndex        =   11
  171.          Top             =   1320
  172.          Width           =   1695
  173.       End
  174.       Begin VB.TextBox Text3 
  175.          Enabled         =   0   'False
  176.          Height          =   285
  177.          Left            =   1440
  178.          TabIndex        =   9
  179.          Top             =   960
  180.          Width           =   1695
  181.       End
  182.       Begin VB.TextBox Text2 
  183.          Enabled         =   0   'False
  184.          Height          =   285
  185.          Left            =   1440
  186.          TabIndex        =   7
  187.          Top             =   600
  188.          Width           =   1695
  189.       End
  190.       Begin VB.TextBox Text1 
  191.          Enabled         =   0   'False
  192.          Height          =   285
  193.          Left            =   1440
  194.          TabIndex        =   4
  195.          Top             =   240
  196.          Width           =   1695
  197.       End
  198.       Begin VB.Label Label12 
  199.          Caption         =   "MAKE"
  200.          Height          =   255
  201.          Left            =   120
  202.          TabIndex        =   23
  203.          Top             =   2400
  204.          Width           =   735
  205.       End
  206.       Begin VB.Label Label11 
  207.          Caption         =   "Label11"
  208.          Height          =   15
  209.          Left            =   240
  210.          TabIndex        =   22
  211.          Top             =   2640
  212.          Width           =   735
  213.       End
  214.       Begin VB.Label Label10 
  215.          Caption         =   "STOCK"
  216.          Height          =   255
  217.          Left            =   120
  218.          TabIndex        =   21
  219.          Top             =   2040
  220.          Width           =   1095
  221.       End
  222.       Begin VB.Label Label5 
  223.          Caption         =   "ASSEMBLY"
  224.          Height          =   375
  225.          Left            =   120
  226.          TabIndex        =   12
  227.          Top             =   1680
  228.          Width           =   1335
  229.       End
  230.       Begin VB.Label Label4 
  231.          Caption         =   "COMPAT PARTS"
  232.          Height          =   255
  233.          Left            =   120
  234.          TabIndex        =   10
  235.          Top             =   1320
  236.          Width           =   1335
  237.       End
  238.       Begin VB.Label Label3 
  239.          Caption         =   "PRICE"
  240.          Height          =   255
  241.          Left            =   120
  242.          TabIndex        =   8
  243.          Top             =   960
  244.          Width           =   1095
  245.       End
  246.       Begin VB.Label Label2 
  247.          Caption         =   "DESCRIPTION"
  248.          Height          =   375
  249.          Left            =   120
  250.          TabIndex        =   6
  251.          Top             =   600
  252.          Width           =   1215
  253.       End
  254.       Begin VB.Label Label1 
  255.          Caption         =   "PARTID"
  256.          Height          =   255
  257.          Left            =   120
  258.          TabIndex        =   5
  259.          Top             =   240
  260.          Width           =   735
  261.       End
  262.    End
  263.    Begin VB.Label Label8 
  264.       Caption         =   "Select Assembly"
  265.       Height          =   255
  266.       Left            =   120
  267.       TabIndex        =   18
  268.       Top             =   120
  269.       Width           =   2895
  270.    End
  271.    Begin VB.Label Label7 
  272.       Caption         =   "Click On a Part From Assembly - Use the mouse to Rotate the Assembly"
  273.       Height          =   255
  274.       Left            =   4320
  275.       TabIndex        =   17
  276.       Top             =   120
  277.       Width           =   5895
  278.    End
  279.    Begin VB.Label Label6 
  280.       Caption         =   "TOTAL"
  281.       Height          =   255
  282.       Left            =   4440
  283.       TabIndex        =   14
  284.       Top             =   7380
  285.       Width           =   1455
  286.    End
  287.    Begin VB.Menu MENU_FILE 
  288.       Caption         =   "&File"
  289.       Begin VB.Menu MENU_EXIT 
  290.          Caption         =   "E&xit"
  291.       End
  292.    End
  293.    Begin VB.Menu MENU_HELP 
  294.       Caption         =   "&Help"
  295.       Begin VB.Menu MENU_ABOUT 
  296.          Caption         =   "&About..."
  297.       End
  298.    End
  299. End
  300. Attribute VB_Name = "Form1"
  301. Attribute VB_GlobalNameSpace = False
  302. Attribute VB_Creatable = False
  303. Attribute VB_PredeclaredId = True
  304. Attribute VB_Exposed = False
  305. Option Explicit
  306.  
  307. 'The model used by this sample, engine1.x, is provided courtesy of Viewpoint
  308. 'Digital, Inc. (www.viewpoint.com).  It is provided for use with this sample
  309. 'only and cannot be distributed with any application without prior written
  310. 'consent.  V6 Engine Model copyright 1999 Viewpoint Digital, Inc..
  311.  
  312. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  313. '
  314. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  315. '
  316. '  File:       auto.frm
  317. '  Content:    Example of display and picking geometry
  318. '
  319. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  320.  
  321. Dim m_assemblies(100) As CD3DFrame
  322. Dim m_assemblyName(100) As String
  323. Dim m_nAssembly As Long
  324.  
  325. Dim m_scene As CD3DFrame
  326. Dim m_root As CD3DFrame
  327. Dim m_bMouseDown As Boolean
  328. Dim m_lastX As Integer
  329. Dim m_lastY As Integer
  330. Dim m_current As CD3DFrame
  331.  
  332. Dim m_bInLoad As Boolean
  333. Dim m_binit As Boolean
  334. Dim m_data As New Data
  335. Dim fLoading As Boolean
  336. Dim m_backcolor As Long
  337. Dim m_mediadir As String
  338.  
  339. Implements DirectXEvent8
  340.  
  341.  
  342.  
  343. Private Sub DirectXEvent8_DXCallback(ByVal eventid As Long)
  344.     Dim b As Boolean
  345.     
  346. End Sub
  347.  
  348. '- Form_Load
  349. '
  350. '  Initialize the D3DUtil Framework
  351. '  Initialize the parts info text database
  352. '  Initialize the treeview control
  353.  
  354. Private Sub Form_Load()
  355.     Dim b As Boolean
  356.     
  357.     Me.Show
  358.     DoEvents
  359.     
  360.     ' Initialize D3D Window
  361.     b = D3DUtil_DefaultInitWindowed(0, largepict.hwnd)
  362.     If b = False Then
  363.         MsgBox "Exiting, Unable to initialize 3D device"
  364.         End
  365.     End If
  366.     
  367.     'Add some default light and turn on lighting
  368.     g_lWindowWidth = largepict.ScaleWidth
  369.     g_lWindowHeight = largepict.ScaleHeight
  370.     D3DUtil.D3DUtil_SetupDefaultScene
  371.     
  372.     'Find Media Directory
  373.     m_mediadir = FindMediaDir("partstable.txt", False)
  374.     
  375.     'Open Text Database
  376.     m_data.InitData m_mediadir + "partstable.txt"
  377.                
  378.     'Save our initial background color
  379.     m_backcolor = &HFF90D090
  380.   
  381.     'Fill the Tree view with its root node
  382.     FillTreeViewControl
  383.     
  384.         
  385. End Sub
  386.  
  387.      
  388. '- SelectPart
  389. '
  390. '  fill in the text boxes given a certain identifier
  391. '  from a model. We query the database for the identifier
  392. '  and from there we get the rest of the info
  393. Sub SelectPart(strName As String, strObject As String)
  394.    
  395.    If m_data.MoveToModelPartRecord(strName) = False Then Exit Sub
  396.    
  397.    Text1.Text = m_data.PartID
  398.    Text2.Text = m_data.Description
  399.    Text3.Text = format$(m_data.Price, "#0.00")
  400.    Text4.Text = m_data.CompatibleParts
  401.    Text5.Text = "Engine"
  402.    Text6.Text = m_data.Stock
  403.    Text7.Text = m_data.PartMake
  404.    
  405.    If Not m_root Is Nothing Then
  406.         
  407.         'Turn the selected object red
  408.         If Not m_current Is Nothing Then
  409.             With m_current.GetChildMesh(0)
  410.                 .bUseMaterials = True
  411.                 .bUseMaterialOverride = False
  412.             End With
  413.         End If
  414.         
  415.         Set m_current = m_scene.FindChildObject(strObject, 0)
  416.         
  417.         If Not (m_current Is Nothing) Then
  418.             Dim mat As D3DMATERIAL8
  419.             With m_current.GetChildMesh(0)
  420.                 .bUseMaterials = False
  421.                 .bUseMaterialOverride = True
  422.                 mat.emissive.r = 0.5
  423.                 mat.emissive.a = 1
  424.                 mat.diffuse.r = 0.3
  425.                 mat.diffuse.a = 1
  426.                 .SetMaterialOverride mat
  427.             End With
  428.         End If
  429.     End If
  430.    
  431.    
  432. errOut:
  433. End Sub
  434.  
  435.  
  436. '- Rotate Track ball
  437. '  given a point on the screen the mouse was moved to
  438. '  simulate a track ball
  439. Private Sub RotateTrackBall(x As Integer, y As Integer)
  440.  
  441.     
  442.     Dim delta_x As Single, delta_y As Single
  443.     Dim delta_r As Single, radius As Single, denom As Single, angle As Single
  444.     
  445.     ' rotation axis in camcoords, worldcoords, sframecoords
  446.     Dim axisC As D3DVECTOR
  447.     Dim wc As D3DVECTOR
  448.     Dim axisS As D3DVECTOR
  449.     Dim base As D3DVECTOR
  450.     Dim origin As D3DVECTOR
  451.     
  452.     delta_x = x - m_lastX
  453.     delta_y = y - m_lastY
  454.     m_lastX = x
  455.     m_lastY = y
  456.  
  457.             
  458.      delta_r = Sqr(delta_x * delta_x + delta_y * delta_y)
  459.      radius = 50
  460.      denom = Sqr(radius * radius + delta_r * delta_r)
  461.     
  462.     If (delta_r = 0 Or denom = 0) Then Exit Sub
  463.     angle = (delta_r / denom)
  464.  
  465.     axisC.x = (-delta_y / delta_r)
  466.     axisC.y = (-delta_x / delta_r)
  467.     axisC.z = 0
  468.  
  469.  
  470.     'transform camera space vector to world space
  471.     'm_largewindow.m_cameraFrame.Transform wc, axisC
  472.     g_dev.GetTransform D3DTS_VIEW, g_viewMatrix
  473.     D3DXVec3TransformCoord wc, axisC, g_viewMatrix
  474.     
  475.     
  476.     'transform world space vector into Model space
  477.     m_scene.UpdateFrames
  478.     axisS = m_root.InverseTransformCoord(wc)
  479.         
  480.     'transform origen camera space to world coordinates
  481.     'm_largewindow.m_cameraFrame.Transform  wc, origin
  482.     D3DXVec3TransformCoord wc, origin, g_viewMatrix
  483.     
  484.     'transfer cam space origen to model space
  485.     base = m_root.InverseTransformCoord(wc)
  486.     
  487.     axisS.x = axisS.x - base.x
  488.     axisS.y = axisS.y - base.y
  489.     axisS.z = axisS.z - base.z
  490.     
  491.     m_root.AddRotation COMBINE_BEFORE, axisS.x, axisS.y, axisS.z, angle
  492.     
  493. End Sub
  494.  
  495. '- LoadAssembly
  496. '
  497. '  See if we have the assembly loaded
  498. '  if not figure out which model to use from a db
  499. '  and load it
  500. '  by default it will attach it to the scene
  501. Function LoadAssembly(sname As String) As Long
  502.     
  503.     
  504.     Dim i As Long
  505.     Dim strCap As String
  506.     Dim strModel As String
  507.     
  508.     Static b As Boolean
  509.     
  510.     If b = True Then Exit Function
  511.     b = True
  512.     
  513.     'make sure we dont habe it already
  514.     For i = 1 To m_nAssembly
  515.         If sname = m_assemblyName(i) Then
  516.             LoadAssembly = i
  517.             b = False
  518.             Exit Function
  519.         End If
  520.     Next
  521.     
  522.     
  523.     m_nAssembly = m_nAssembly + 1
  524.     m_assemblyName(m_nAssembly) = sname
  525.     
  526.     
  527.     'look up the model we need to load
  528.     'for this example we only show 1 model
  529.     'but one could query for the files from a database
  530.     strModel = "engine1.x"
  531.     strCap = Me.Caption
  532.     Me.Caption = "Loading- please wait"
  533.     DoEvents
  534.     Err.Number = 0
  535.  
  536.     Form2.Top = Me.Top + Me.height / 4
  537.     Form2.Left = Me.Left + Me.width / 8
  538.     Form2.Show
  539.     DoEvents
  540.     
  541.     Set m_assemblies(m_nAssembly) = New CD3DFrame
  542.     b = m_assemblies(m_nAssembly).InitFromFile(g_dev, m_mediadir + strModel, Nothing, Nothing)
  543.         
  544.     
  545.     If b = False Then
  546.         Set m_assemblies(m_nAssembly) = Nothing
  547.         m_assemblyName(m_nAssembly) = ""
  548.         m_nAssembly = m_nAssembly - 1
  549.         Unload Form2
  550.         Me.Caption = strCap
  551.         GoTo errOut
  552.     End If
  553.     Me.Caption = strCap
  554.     
  555.     m_assemblies(m_nAssembly).SetFVF g_dev, D3DFVF_VERTEX
  556.     m_assemblies(m_nAssembly).ComputeNormals
  557.     
  558.     g_dev.SetRenderState D3DRS_AMBIENT, &H90909090
  559.     
  560.     
  561.     'Release the previous scene
  562.     Set m_scene = Nothing
  563.     Set m_root = Nothing
  564.     Set m_current = Nothing
  565.     
  566.     'Create a root object for the scene
  567.     Set m_scene = New CD3DFrame
  568.  
  569.     'Create a new root object to use for rotation matrix
  570.     Set m_root = D3DUtil_CreateFrame(m_scene)
  571.     
  572.     
  573.     
  574.     'Add our assembly to the tree
  575.     m_root.AddChild m_assemblies(m_nAssembly)
  576.        
  577.     
  578.     'Position our assembly
  579.     m_assemblies(m_nAssembly).AddTranslation COMBINE_replace, 0, 0, 5
  580.     
  581.     
  582.     
  583.     'Recolor m_assemblies(m_nAssembly)
  584.         
  585.     LoadAssembly = m_nAssembly
  586.     
  587.     
  588.     Unload Form2
  589.     DoEvents
  590.     If fLoading Then End
  591.     
  592.     RenderScene
  593.     
  594.     DoEvents
  595.     
  596.     Set m_root = m_assemblies(m_nAssembly)
  597.     
  598.     
  599.     m_binit = True
  600.     
  601. errOut:
  602.     
  603.     
  604.     b = False
  605.     
  606.     
  607.     TreeView1.Enabled = True
  608.     largepict.SetFocus
  609.     DoEvents
  610.     
  611. End Function
  612.  
  613.      
  614. ' Command1_Click
  615. ' Add To Invoice
  616. '
  617. Private Sub Command1_Click()
  618.  
  619.     Dim itm As ListItem
  620.     If Text1.Text = "" Then Exit Sub
  621.     
  622.     Set itm = ListView1.ListItems.Add(, , Text2.Text)
  623.     itm.SubItems(1) = Text3.Text
  624.     itm.SubItems(2) = Text1.Text
  625.     Set ListView1.SelectedItem = itm
  626.     itm.EnsureVisible
  627.     Text8.Text = format(val(Text8.Text) + val(Text3.Text), "#0.00")
  628.     
  629. End Sub
  630.  
  631.  
  632. ' Command1_Click
  633. ' Delete from Invoice
  634. '
  635. Private Sub Command2_Click()
  636.     If ListView1.SelectedItem Is Nothing Then Exit Sub
  637.     
  638.     Text8 = format(val(Text8.Text) - val(ListView1.SelectedItem.SubItems(1)), "#0.00")
  639.     ListView1.ListItems.Remove ListView1.SelectedItem.index
  640. End Sub
  641.  
  642.        
  643.     
  644. ' Form_QueryUnload
  645. '
  646. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  647.     fLoading = True
  648. End Sub
  649.  
  650.  
  651.  
  652. '- MouseDown
  653. '
  654. Private Sub largepict_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  655.     
  656.     If m_binit = False Then Exit Sub
  657.     
  658.     Dim b As Boolean
  659.     Dim mb As CD3DMesh
  660.     Dim r As Integer, c As Integer
  661.     Dim f As CD3DFrame
  662.     Dim p As CD3DFrame
  663.     Dim strName As String
  664.     Dim pick As CD3DPick
  665.     Dim n As Long
  666.     
  667.     '- save our current position
  668.     m_bMouseDown = True
  669.     m_lastX = x
  670.     m_lastY = y
  671.     
  672.     
  673.     If Button = 1 Then
  674.         
  675.         'Get the frame under the the mouse
  676.         Set pick = New CD3DPick
  677.         If Not pick.ViewportPick(m_scene, x, y) Then Exit Sub
  678.                        
  679.                         
  680.         n = pick.FindNearest()
  681.         If n < 0 Then Exit Sub
  682.         Set f = pick.GetFrame(n)
  683.         
  684.                 
  685.         'Get its id and call SelectPart
  686.         'to fill in our text boxes
  687.         strName = f.ObjectName
  688.         strName = Right$(strName, Len(strName) - 1)
  689.         'The words V6 and Chevy are part of the manifold cover.
  690.         If strName = "words" Or strName = "v6" Then strName = "manifoldt"
  691.         
  692.         SelectPart strName, f.ObjectName
  693.         SelectTreeview strName
  694.         DoEvents
  695.         
  696.     End If
  697.     
  698.     RenderScene
  699.     
  700. End Sub
  701.  
  702. '- MOUSE MOVE
  703. '
  704. Private Sub largepict_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  705.     
  706.     '- dont do anything unless the mouse is down
  707.     If m_bMouseDown = False Then
  708.         Exit Sub
  709.     End If
  710.     
  711.     '- Rotate the object
  712.     RotateTrackBall CInt(x), CInt(y)
  713.     
  714.     '- Rerender
  715.     RenderScene
  716.         
  717. End Sub
  718.  
  719. '- MOUSE UP
  720. '  reset the mouse state
  721. '
  722. Private Sub largepict_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  723.     m_bMouseDown = False
  724. End Sub
  725.  
  726. '- largepict_Paint UP
  727. '
  728. Private Sub largepict_Paint()
  729.     If Not m_binit Then Exit Sub
  730.     RenderScene
  731. End Sub
  732.  
  733.  
  734. '- MENU_ABOUT_Click
  735. '
  736. Private Sub MENU_ABOUT_Click()
  737.     MsgBox "The model used by this sample, engine1.x, is provided courtesy of Viewpoint" + Chr(10) + Chr(13) + _
  738.         "Digital, Inc. (www.viewpoint.com).  It is provided for use with this sample" + Chr(10) + Chr(13) + _
  739.         "only and cannot be distributed with any application without prior written" + Chr(10) + Chr(13) + _
  740.         "consent.  V6 Engine Model copyright 1999 Viewpoint Digital, Inc.."
  741. End Sub
  742.  
  743. ' MENU_EXIT_Click
  744. '
  745. Private Sub MENU_EXIT_Click()
  746.     End
  747. End Sub
  748.  
  749.  
  750. ' TreeView1_Expand
  751. '
  752. Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
  753.     Dim i As Long
  754.     
  755.     Static b As Boolean
  756.         
  757.     If b Then Exit Sub
  758.     b = True
  759.         
  760.     'See if they are asking for a new assembly alltogether
  761.     If Mid$(Node.Tag, 1, 8) = "ASSMBLY:" Then
  762.         m_bInLoad = True
  763.         i = LoadAssembly(Node.Tag)
  764.         If i = 0 Then
  765.             MsgBox "Assembly not available at this time- try a different Engine"
  766.             b = False
  767.             Exit Sub
  768.         End If
  769.         
  770.     End If
  771.     
  772.     b = False
  773.     
  774. End Sub
  775.  
  776. '- TreeView1_NodeClick
  777. '
  778. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
  779.             
  780.     Static b As Boolean
  781.     If b Then Exit Sub
  782.     b = True
  783.  
  784.     Dim o As CD3DFrame
  785.     Dim i  As Long
  786.     
  787.     If Node.Tag = "" Then
  788.         b = False
  789.         Exit Sub
  790.     End If
  791.     
  792.     'Fill in the text boxes
  793.     SelectPart Node.Tag, "_" & Node.Tag
  794.     DoEvents
  795.         
  796.     'Render
  797.     RenderScene
  798.     DoEvents
  799.     
  800.     b = False
  801. End Sub
  802.  
  803.  
  804.  
  805. '- FillTreeViewControl
  806. Sub FillTreeViewControl()
  807.     TreeView1.Nodes.Clear
  808.     
  809.     Dim sPartID As String
  810.     Dim sDesc As String
  811.     
  812.     
  813.     'A non-demo application would build the tree view
  814.     'from the database and dynamically load in new
  815.     'information into the treeview
  816.     
  817.     Dim n As Node
  818.     Call TreeView1.Nodes.Add(, , "ASSEMBLIES", "Assemblies - [click here to start]")
  819.     
  820.     Set n = TreeView1.Nodes.Add("ASSEMBLIES", tvwChild, "ENG V6 1996", "V6 4 Liter 1996 - [click here]")
  821.     n.Tag = "ASSMBLY:ENG V6 1996"
  822.     n.Selected = True
  823.     
  824.     TreeView1.Nodes.Add("ASSEMBLIES", tvwChild, "ENG V8 1998", "V8 6 Liter 1998 - [not available]").Tag = ""
  825.     TreeView1.Nodes.Add("ASSEMBLIES", tvwChild, "OTHERENG", "Other Assemblies not available").Tag = ""
  826.     
  827.     m_data.MoveTop
  828.     Do While m_data.IsEOF() = False
  829.         sPartID = m_data.ModelPart
  830.         sDesc = m_data.Description
  831.         TreeView1.Nodes.Add("ENG V6 1996", tvwChild, sPartID, sDesc).Tag = sPartID
  832.         m_data.MoveNext
  833.     Loop
  834.     
  835. End Sub
  836.  
  837. Sub SelectTreeview(sname As String)
  838.     On Local Error Resume Next
  839.     TreeView1.Nodes(sname).Selected = True
  840.     DoEvents
  841. End Sub
  842.  
  843.  
  844. '- RenderScene
  845. '
  846. Sub RenderScene()
  847.     Dim hr As Long
  848.     
  849.     If m_scene Is Nothing Then Exit Sub
  850.     
  851.      
  852.     
  853.     'See what state the device is in.
  854.     hr = g_dev.TestCooperativeLevel
  855.     If hr = D3DERR_DEVICENOTRESET Then
  856.         g_dev.Reset g_d3dpp
  857.         
  858.         'reset our state
  859.         g_lWindowWidth = largepict.ScaleWidth
  860.         g_lWindowHeight = largepict.ScaleHeight
  861.         D3DUtil.D3DUtil_SetupDefaultScene
  862.         DoEvents
  863.     ElseIf hr <> 0 Then
  864.         Exit Sub
  865.     End If
  866.     
  867.     D3DXMatrixLookAtLH g_viewMatrix, vec3(0, 0, -1), vec3(0, 0, 0), vec3(0, 1, 0)
  868.     g_dev.SetTransform D3DTS_VIEW, g_viewMatrix
  869.  
  870.     D3DUtil_ClearAll m_backcolor
  871.     g_dev.BeginScene
  872.     m_scene.Render g_dev
  873.     g_dev.EndScene
  874.     D3DUtil_PresentAll 0
  875.     
  876. End Sub
  877.